﻿using System;

using BEGDC.CC.BL.Workflow;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using BEGDC.Utility.Castle;
using BEGDC.CC.Entity;

namespace BEGDC.CC.Web.UserControls
{
	/// <summary>
	/// Summary description for AccessControl.
	/// </summary>
	public class CRAccessControl: AccessControl
	{

		public override bool IsReadOnly
		{
			get
			{
				if( base.IsReadOnly )
				{
					return base.IsReadOnly;
				}
				else
				{
					if( this._currentStep == WorkTransition.CR_CATDirectorApproval || this._currentStep == WorkTransition.CR_CATVPApproval
						|| this._currentStep == WorkTransition.CR_PSOHeadApproval || this._currentStep == WorkTransition.CR_DeptDirectorApproval
						|| this._currentStep == WorkTransition.CR_DeptHeadApproval || this._currentStep == WorkTransition.CR_CRSurvey 
						|| this._currentStep == WorkTransition.CR_CloseApp  )
					{
						return true;
					}
					else
						return false;
				}
			}
		}

		public override bool IsAttachmentReadOnly
		{
			get
			{
				if( this._currentStep == WorkTransition.CR_CATDirectorApproval || this._currentStep == WorkTransition.CR_CATVPApproval
					|| this._currentStep == WorkTransition.CR_PSOHeadApproval || this._currentStep == WorkTransition.CR_DeptDirectorApproval
					|| this._currentStep == WorkTransition.CR_DeptHeadApproval || this._currentStep == WorkTransition.CR_CRSurvey)
				{
					return true;
				}
				else if(this._currentStep == WorkTransition.End && this._state!=SysDicItem.ProjectStatusFlag.Archive)
				{
					if(_state == SysDicItem.ProjectStatusFlag.Participation)
						return !this._isMgrOrStaff;
					else
						return true;
				}
				else
					return base.IsAttachmentReadOnly;
			}
		}

		public override bool IsButtonVisible(string name)
		{
			if(this.IsQuery)
			{
				switch(name)
				{
					case CRTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case CRTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					case CRTransitionList.Save:
						return this.ShowSaveButton();
						break;
					default:
						return false;
				}
			}
			else
			{
				switch(name)
				{
					case CRTransitionList.Copy:
						return this.ShowCopyButton();
						break;
					case CRTransitionList.Reply:
						return this.ShowReplyButton();
						break;
					default:
					switch(this._currentStep)
					{
						case WorkTransition.Draft:
							if(name == CRTransitionList.Submit || name == CRTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CR_Request:
							if(name == CRTransitionList.Submit || name == CRTransitionList.Save || name == CRTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CR_ReRequest:
							if(name == CRTransitionList.Submit || name == CRTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CR_AssignApp:
							if(name == CRTransitionList.Assign || name == CRTransitionList.Reject || name == CRTransitionList.Save
								|| name == CRTransitionList.Check || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_CheckApp:
							if(name == CRTransitionList.Reject || name == CRTransitionList.Check || name == CRTransitionList.Query
								|| name == CRTransitionList.Save)
								return true;
							else
								return false;
						case WorkTransition.CR_CATDirectorApproval:
							if( name == CRTransitionList.Reject || name == CRTransitionList.Approve || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_CATVPApproval:
							if( name == CRTransitionList.Reject || name == CRTransitionList.Approve || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_PSOHeadApproval:
							if( name == CRTransitionList.Reject || name == CRTransitionList.Approve || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_DeptDirectorApproval:
							if( name == CRTransitionList.Reject || name == CRTransitionList.Approve || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_DeptHeadApproval:
							if( name == CRTransitionList.Reject || name == CRTransitionList.Approve || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_FNCApproval:
							if( name == CRTransitionList.Reject || name == CRTransitionList.Approve || name == CRTransitionList.Query)
								return true;
							else
								return false;
						case WorkTransition.CR_CRSurvey:
							if( name == CRTransitionList.Save || name == CRTransitionList.Submit || name == CRTransitionList.Reply)
								return true;
							else
								return false;
						case WorkTransition.CR_CloseApp:
							if( name == CRTransitionList.Save || name == CRTransitionList.Close)// || name == CRTransitionList.Query)
								return true;
							else
								return false;
					}
						return false;
						break;
				}
			}
		}
		
	}	
}

